<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>范例</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="xhprof.constants.html">« 预定义常量</a></li>
      <li style="float: right;"><a href="ref.xhprof.html">Xhprof 函数 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.xhprof.html">Xhprof</a></li>
    <li>范例</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="xhprof.examples" class="chapter">
 <h1>范例</h1>

 <div class="example" id="example-680">
  <p><strong>示例 #1 Xhprof 范例，可选使用图形界面</strong></p>
  <div class="example-contents"><p>
   本示例启动并结束性能分析器，然后使用捆绑的用户界面来保存和解析结果。
   换言之，扩展的代码在调用 <span class="function"><a href="function.xhprof-disable.html" class="function">xhprof_disable()</a></span> 函数后结束。
  </p></div>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />xhprof_enable</span><span style="color: #007700">(</span><span style="color: #0000BB">XHPROF_FLAGS_CPU&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">XHPROF_FLAGS_MEMORY</span><span style="color: #007700">);<br /><br />for&nbsp;(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;=&nbsp;</span><span style="color: #0000BB">1000</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">++)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$xhprof_data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">xhprof_disable</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$XHPROF_ROOT&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"/tools/xhprof/"</span><span style="color: #007700">;<br />include_once&nbsp;</span><span style="color: #0000BB">$XHPROF_ROOT&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"/xhprof_lib/utils/xhprof_lib.php"</span><span style="color: #007700">;<br />include_once&nbsp;</span><span style="color: #0000BB">$XHPROF_ROOT&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"/xhprof_lib/utils/xhprof_runs.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$xhprof_runs&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">XHProfRuns_Default</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$run_id&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$xhprof_runs</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">save_run</span><span style="color: #007700">(</span><span style="color: #0000BB">$xhprof_data</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"xhprof_testing"</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"http://localhost/xhprof/xhprof_html/index.php?run=</span><span style="color: #007700">{</span><span style="color: #0000BB">$run_id</span><span style="color: #007700">}</span><span style="color: #DD0000">&amp;source=xhprof_testing\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

  <div class="example-contents"><p>以上例程的输出类似于：</p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
http://localhost/xhprof/xhprof_html/index.php?run=t11_4bdf44d21121f&amp;source=xhprof_testing
</pre></div>
  </div>
 </div>
</div>
</div></div></body></html>